const mongoose = require("mongoose")
const crypto = require("crypto") //引用加密模块
const UserSchema = new mongoose.Schema({
    mobile: String, //手机号
    pwd: String, //密码
    isAdmin: Boolean //是否是管理员
}, {
    versionKey: false,
    timestamps: {
        createdAt: 'createTime',
        updatedAt: 'updateTime'
    } //自动管理修改时间
})
const user = mongoose.model("User", UserSchema);
async function add() {
    const md5 = crypto.createHash("md5");
    const count = await user.countDocuments();
    if (count == 0) {
        user.create({
            mobile: "18381914662",
            pwd: md5.update("666").digest("hex"),
            isAdmin: true
        })
    }
}
add();
module.exports = user;